package com.yikome.product.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.yikome.common.CommonRepository;
import com.yikome.product.entity.Category;

@Repository
public interface CategoryRepository extends CommonRepository<Category, Long>{

	@Query("select c from Category c where c.yn = 1 order by c.priority asc")
	List<Category> findAllCategory();

	@Query("select c from Category c where c.yn = 1 and c.parentId = :parentId order by c.priority asc")
	List<Category> findByParentId(@Param("parentId")Long parentId);

	long countByParentIdAndYn(Long parentId , Integer yn);

	@Query("select c from Category c where c.yn = 1 and c.parentId = :parentId and c.name= :name order by c.priority asc")
	Category findByParentIdAndName(@Param("parentId")Long parentId, @Param("name")String name);

}
